home *** CD-ROM | disk | FTP | other *** search
- {*********************************************************}
- {* OVCBTNHD.PAS 3.00 *}
- {* Copyright (c) 1995-99 TurboPower Software Co *}
- {* All rights reserved. *}
- {*********************************************************}
-
- {$I OVC.INC}
-
- {$B-} {Complete Boolean Evaluation}
- {$I+} {Input/Output-Checking}
- {$P+} {Open Parameters}
- {$T-} {Typed @ Operator}
- {$W-} {Windows Stack Frame}
- {$X+} {Extended Syntax}
-
- {$IFNDEF Win32}
- {$G+} {286 Instructions}
- {$N+} {Numeric Coprocessor}
-
- {$C MOVEABLE,DEMANDLOAD,DISCARDABLE}
- {$ENDIF}
-
- unit OvcBtnHd;
- {-Button header component}
-
- interface
-
- uses
- {$IFDEF Win32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF}
- Buttons, Classes, Controls, Dialogs, ExtCtrls, Forms,
- Graphics, Menus, Messages, SysUtils,
- {$IFNDEF Win32} OvcImLst, {$ENDIF}
- OvcBase, OvcConst, OvcData, OvcMisc;
-
- type
- TOvcButtonHeaderStyle = (bhsNone, bhsRadio, bhsButton);
- {$IFDEF Win32}
- TOvcBHDrawingStyle = (bhsDefault, bhsThin, bhsFlat, bhsEtched);
- {$ENDIF}
- TOvcButtonHeaderSection = class(TOvcCollectible)
- {.Z+}
- protected {private}
- {property variables}
- FAlignment : TAlignment;
- FCaption : string;
- FImageIndex : Integer;
- FPaintRect : TRect;
- FWidth : Integer;
-
- protected
- {property methods}
- procedure SetAlignment(Value : TAlignment);
- procedure SetCaption(const Value : string);
- procedure SetImageIndex(Value : Integer);
- procedure SetWidth(Value : Integer);
-
- function GetBaseName : string;
- override;
- function GetDisplayText : string;
- override;
-
- public
- constructor Create(AOwner : TComponent);
- override;
- property PaintRect : TRect
- read fPaintRect;
-
- published
- {.Z-}
- property Alignment : TAlignment
- read FAlignment write SetAlignment
- default taLeftJustify;
- property Caption : string
- read FCaption write SetCaption;
- property ImageIndex : Integer
- read FImageIndex write SetImageIndex
- default -1;
- property Width : Integer
- read FWidth write SetWidth
- default 75;
- end;
-
- TOvcTextAttrEvent = procedure(Sender : TObject; Canvas : TCanvas; Index : Integer)
- of object;
-
- TOvcButtonHeader = class(TOvcCustomControl)
- {.Z+}
- protected {private}
- {property variables}
- FAllowResize : Boolean;
- FBorderStyle : TBorderStyle;
- {$IFDEF Win32}
- FDrawingStyle : TOvcBHDrawingStyle;
- {$ENDIF}
- FImages : TImageList;
- FItemIndex : Integer;
- FPushRect : TRect;
- FSections : TOvcCollection;
- FStyle : TOvcButtonHeaderStyle;
- FTextMargin : Integer;
- FWordWrap : Boolean;
-
- {event variables}
- FOnChangeTextAttr : TOvcTextAttrEvent;
- FOnClick : TNotifyEvent;
- FOnSized : TSectionEvent;
- FOnSizing : TSectionEvent;
-
- {internal variables}
- bhCanResize : Boolean;
- bhHitTest : TPoint;
- bhMouseOffset : Integer;
- bhResizeSection : Integer;
- bhSectionPressed: Integer;
- bhDraw : TBitMap;
-
- SectionChanged : Boolean;
-
- {property methods}
- function GetWidth(X : Integer) : Integer;
- function GetSection(Index : Integer) : TOvcButtonHeaderSection;
- function GetSectionCount : Integer;
- procedure SetBorderStyle(Value : TBorderStyle);
- {$IFDEF Win32}
- procedure SetDrawingStyle(const Value: TOvcBHDrawingStyle);
- {$ENDIF}
- procedure SetImages(Value : TImageList);
- procedure SetItemIndex(Value : Integer);
- procedure SetSection(Index : Integer; Value : TOvcButtonHeaderSection);
- procedure SetTextMargin(Value : Integer);
- procedure SetWordWrap(Value : Boolean);
- procedure SetStyle(Value : TOvcButtonHeaderStyle);
-
- {internal methods}
- procedure bhCollectionChanged(Sender : TObject);
- procedure bhGetEditorCaption(var Caption : string);
-
- {VCL control methods}
- procedure CMDialogChar(var Msg : TCMDialogChar);
- message CM_DIALOGCHAR;
- procedure CMDesignHitTest(var Msg : TCMDesignHitTest);
- message CM_DESIGNHITTEST;
-
- {windows message response methods}
- procedure WMSetCursor(var Msg : TWMSetCursor);
- message WM_SETCURSOR;
- procedure WMNCHitTest(var Msg : TWMNCHitTest);
- message WM_NCHITTEST;
-
- protected
- procedure CreateParams(var Params : TCreateParams);
- override;
- procedure MouseDown(Button : TMouseButton; Shift : TShiftState; X, Y : Integer);
- override;
- procedure MouseMove(Shift : TShiftState; X, Y : Integer);
- override;
- procedure MouseUp(Button : TMouseButton; Shift : TShiftState; X, Y : Integer);
- override;
- procedure Notification(AComponent : TComponent; Operation: TOperation);
- override;
- procedure Paint;
- override;
-
- procedure DoOnChangeTextAttr(Canvas : TCanvas;Index : Integer);
- dynamic;
- procedure DoOnClick;
- virtual;
- procedure DoOnSized(ASection, AWidth : Integer);
- dynamic;
- procedure DoOnSizing(ASection, AWidth : Integer);
- dynamic;
-
- public
- constructor Create(AOwner : TComponent);
- override;
- destructor Destroy;
- override;
- {.Z-}
-
- {public properties}
- {.Z+}
- property PushRect : TRect read fPushRect;
- {.Z-}
- property Section[Index : Integer] : TOvcButtonHeaderSection
- read GetSection write SetSection;
- property SectionCount : Integer
- read GetSectionCount;
-
- published
- {properties}
- property AllowResize : Boolean
- read FAllowResize write FAllowResize
- default True;
- property BorderStyle : TBorderStyle
- read FBorderStyle write SetBorderStyle
- default bsNone;
- {$IFDEF Win32}
- property DrawingStyle : TOvcBHDrawingStyle
- read FDrawingStyle write SetDrawingStyle
- default bhsDefault;
- {$ENDIF}
- property Images : TImageList
- read FImages write SetImages;
- property ItemIndex : Integer
- read FItemIndex write SetItemIndex;
- property LabelInfo;
- property Sections : TOvcCollection
- read FSections write FSections;
- property Style : TOvcButtonHeaderStyle
- read FStyle write SetStyle
- default bhsRadio;
- property TextMargin : Integer
- read FTextMargin write SetTextMargin
- default 0;
- property WordWrap : Boolean
- read FWordWrap write SetWordWrap
- default False;
-
- {events}
- property OnClick : TNotifyEvent
- read FOnClick write FOnClick;
- property OnSizing : TSectionEvent
- read FOnSizing write FOnSizing;
- property OnSized : TSectionEvent
- read FOnSized write FOnSized;
-
- {inherited properties}
- {$IFDEF VERSION4}
- property Anchors;
- property Constraints;
- {$ENDIF}
- property Align;
- property Enabled;
- property Font;
- property ParentFont;
- property ParentShowHint;
- property PopupMenu;
- property ShowHint;
- property TabOrder;
- property TabStop;
- property Visible;
- {inherited events}
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- end;
-
-
- implementation
-
-
- {*** TOvcButtonHeaderSection ***}
-
- constructor TOvcButtonHeaderSection.Create(AOwner : TComponent);
- begin
- inherited Create(AOwner);
-
- FAlignment := taLeftJustify;
- FImageIndex := -1;
- FWidth := 75;
- end;
-
- function TOvcButtonHeaderSection.GetBaseName : string;
- begin
- Result := GetOrphStr(SCSectionBaseName);
- end;
-
- function TOvcButtonHeaderSection.GetDisplayText : string;
-
- function TrimAmpersand(const S : string) : string;
- var
- p : Integer;
- begin
- Result := S;
- p := Pos('&', Result);
- while p <> 0 do begin
- Delete(Result,p,1);
- p := Pos('&',Result);
- end;
- end;
-
- begin
- if Caption > '' then
- Result := TrimAmpersand(Caption) + ': ' + ClassName
- else
- Result := Name + ': ' + ClassName;
- end;
-
- procedure TOvcButtonHeaderSection.SetAlignment(Value : TAlignment);
- begin
- if (Value <> FAlignment) then begin
- FAlignment := Value;
- Changed;
- end;
- end;
-
- procedure TOvcButtonHeaderSection.SetCaption(const Value : string);
- begin
- if Value <> Caption then begin
- FCaption := Value;
- Changed;
- end;
- end;
-
- procedure TOvcButtonHeaderSection.SetImageIndex(Value : Integer);
- begin
- if Value <> ImageIndex then begin
- FImageIndex := Value;
- Changed;
- end;
- end;
-
- procedure TOvcButtonHeaderSection.SetWidth(Value : Integer);
- begin
- if Value <> Width then begin
- FWidth := Value;
- Changed;
- end;
- end;
-
-
- {*** TOvcButtonHeader ***}
-
- procedure TOvcButtonHeader.bhCollectionChanged;
- begin
- Invalidate;
- end;
-
- procedure TOvcButtonHeader.bhGetEditorCaption(var Caption : string);
- begin
- Caption := GetOrphStr(SCEditingSections);
- end;
-
- procedure TOvcButtonHeader.CMDialogChar(var Msg : TCMDialogChar);
- var
- I : Integer;
- begin
- if Enabled then with Msg do begin
- for I := 0 to Pred(FSections.Count) do
- if IsAccel(CharCode, Section[I].Caption) then begin
- ItemIndex := I;
- Result := 1;
- Exit;
- end;
- end;
-
- inherited;
- end;
-
- procedure TOvcButtonHeader.CMDesignHitTest(var Msg : TCMDesignHitTest);
- begin
- if bhCanResize then
- Msg.Result := 1
- else
- inherited;
- end;
-
- constructor TOvcButtonHeader.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
-
- if Classes.GetClass(TOvcButtonHeaderSection.ClassName) = nil then
- Classes.RegisterClass(TOvcButtonHeaderSection);
-
- ControlStyle := ControlStyle + [csOpaque];
-
- Width := 250;
- Height := 20;
-
- FSections := TOvcCollection.Create(Self, TOvcButtonHeaderSection);
- FSections.OnChanged := bhCollectionChanged;
- FSections.OnGetEditorCaption := bhGetEditorCaption;
-
- FAllowResize := True;
- FBorderStyle := bsNone;
- FStyle := bhsRadio;
- FTextMargin := 0;
- FWordWrap := False;
-
- bhSectionPressed := -1;
- end;
-
- procedure TOvcButtonHeader.CreateParams(var Params : TCreateParams);
- const
- BorderStyles: array[TBorderStyle] of Longint = (0, WS_BORDER);
- begin
- inherited CreateParams(Params);
-
- Params.Style := LongInt(Params.Style) or BorderStyles[FBorderStyle];
- {$IFDEF Win32}
- if NewStyleControls and Ctl3D and (FBorderStyle = bsSingle) then begin
- Params.Style := Params.Style and not WS_BORDER;
- Params.ExStyle := Params.ExStyle or WS_EX_CLIENTEDGE;
- end;
- {$ENDIF}
- end;
-
- destructor TOvcButtonHeader.Destroy;
- begin
- if FImages <> nil then
- FImages.OnChange := nil;
- FSections.Free;
- FSections := nil;
-
- bhDraw.Free;
- bhDraw := nil;
- inherited Destroy;
- end;
-
- procedure TOvcButtonHeader.DoOnChangeTextAttr(Canvas : TCanvas; Index : Integer);
- begin
- if Assigned(FOnChangeTextAttr) then
- FOnChangeTextAttr(Self, Canvas, Index);
- end;
-
- procedure TOvcButtonHeader.DoOnClick;
- begin
- Invalidate;
- if Assigned(FOnClick) then
- FOnClick(Self);
- end;
-
- procedure TOvcButtonHeader.DoOnSizing(ASection, AWidth : Integer);
- begin
- if Assigned(FOnSizing) then
- FOnSizing(Self, ASection, AWidth);
- end;
-
- procedure TOvcButtonHeader.DoOnSized(ASection, AWidth : Integer);
- begin
- if Assigned(FOnSized) then
- FOnSized(Self, ASection, AWidth);
- end;
-
- function TOvcButtonHeader.GetSection(Index : Integer) : TOvcButtonHeaderSection;
- begin
- Result := TOvcButtonHeaderSection(FSections[Index]);
- end;
-
- function TOvcButtonHeader.GetSectionCount : Integer;
- begin
- Result := FSections.Count;
- end;
-
- function TOvcButtonHeader.GetWidth(X : Integer) : Integer;
- var
- I, W : Integer;
- begin
- if X = FSections.Count - 1 then begin
- W := 0;
- for I := 0 to X - 1 do
- Inc(W, Section[I].Width);
- Result := ClientWidth - W;
- end else if (X >= 0) and (X < FSections.Count) then
- Result := Section[X].Width
- else
- Result := 0;
- end;
-
- procedure TOvcButtonHeader.MouseDown(Button : TMouseButton; Shift : TShiftState; X, Y : Integer);
- var
- I,J : Integer;
- begin
- SectionChanged := False;
- if bhCanResize then begin
- inherited MouseDown(Button, Shift, X, Y);
- if (Button = mbLeft) then
- SetCapture(Handle);
- end else
- if not (csDesigning in ComponentState) and (Button = mbLeft) then begin
- Y := 2;
- J := -1;
- for I := 0 to FSections.Count - 1 do begin
- Inc(Y, Section[I].Width);
- if Y > X then begin
- J := I;
- Break;
- end;
- end;
- if (J <> -1) and (J < FSections.Count) then begin
- inherited MouseDown(Button, Shift, X, Y);
- case Style of
- bhsRadio :
- begin
- ItemIndex := J;
- Invalidate;
- end;
- bhsButton :
- begin
- bhSectionPressed := J;
- FItemIndex := J;
- Refresh;
- end;
- bhsNone :
- FItemIndex := J;
- end;
- SectionChanged := True;
- end;
- end;
- end;
-
- procedure TOvcButtonHeader.MouseMove(Shift : TShiftState; X, Y : Integer);
- var
- I : Integer;
- AbsPos : Integer;
- MinPos : Integer;
- MaxPos : Integer;
- InvRect: TRect;
- begin
- inherited MouseMove(Shift, X, Y);
-
- if (GetCapture = Handle) and bhCanResize then begin
- {absolute position of this item}
- AbsPos := 2;
- for I := 0 to bhResizeSection do
- Inc(AbsPos, Section[I].Width);
- if bhResizeSection > 0 then MinPos := AbsPos -
- Section[bhResizeSection].Width + 2
- else
- MinPos := 2;
-
- MaxPos := ClientWidth - 2;
- if X < MinPos then
- X := MinPos;
- if X > MaxPos then
- X := MaxPos;
-
- Section[bhResizeSection].Width := Section[bhResizeSection].Width -
- (AbsPos - X - 2) - bhMouseOffset;
- DoOnSizing(bhResizeSection, Section[bhResizeSection].Width);
-
- InvRect.Left := X;
- InvRect.Top := 0;
- InvRect.Bottom := Height-1;
- InvRect.Right := Width-1;
-
- Refresh;
- end;
- end;
-
- procedure TOvcButtonHeader.MouseUp(Button : TMouseButton; Shift : TShiftState; X, Y : Integer);
- begin
- if bhCanResize then begin
- ReleaseCapture;
- DoOnSized(bhResizeSection,
- Section[bhResizeSection].Width);
- bhCanResize := False;
- end else
- case Style of
- bhsButton :
- begin
- bhSectionPressed := -1;
- if SectionChanged then begin
- if PtInRect(ClientRect, Point(X,Y)) then
- DoOnClick;
- Refresh;
- end;
- end;
- bhsNone :
- if SectionChanged then
- if PtInRect(ClientRect, Point(X,Y)) then
- DoOnClick;
- end;
-
- inherited MouseUp(Button, Shift, X, Y);
- end;
-
- procedure TOvcButtonHeader.Notification(AComponent : TComponent; Operation : TOperation);
- begin
- inherited Notification(AComponent, Operation);
-
- if Operation = opRemove then
- if AComponent = FImages then
- Images := nil;
- end;
-
- procedure TOvcButtonHeader.Paint;
- var
- I, W : Integer;
- P : array[0..255] of Char;
- S : string;
- R, R2 : TRect;
- WM, AL : Word;
- {$IFNDEF WIN32}
- Y : Integer;
- {$ENDIF}
- Img,H,T : Integer;
- BDim : TPoint;
- begin
- if (bhDraw <> nil) and ((bhDraw.Width <> Width) or (bhDraw.Height <> Height)) then begin
- bhDraw.Free;
- bhDraw := nil;
- end;
- if bhDraw = nil then begin
- bhDraw := TBitMap.Create;
- bhDraw.Width := Width;
- bhDraw.Height := Height;
- end;
-
- with bhDraw.Canvas do begin
- Font := Self.Font;
- Brush.Color := clBtnFace;
- I := 0;
- {$IFNDEF WIN32}
- Y := (ClientHeight - TextHeight('T')) div 2;
- {$ENDIF}
- R := Rect(0, 0, 0, ClientHeight);
- {$IFDEF Win32}
- if (BorderStyle <> bsNone) and (DrawingStyle <> bhsDefault) then
- InflateRect(R,0,1);
- {$ENDIF}
- W := 0;
- repeat
- AL := 0;
- if I < FSections.Count then begin
- with Section[I] do begin
- W := Width;
- case Alignment of
- taLeftJustify : AL := DT_LEFT;
- taRightJustify : AL := DT_RIGHT;
- taCenter : AL := DT_CENTER;
- end;
- S := Caption;
- Img := ImageIndex;
- if (Images = nil) or (Img >= Images.Count) then
- Img := -1
- end;
- end else begin
- S := '';
- Img := -1;
- end;
- Inc(I);
- R.Left := R.Right;
- Inc(R.Right, W);
- if (ClientWidth - R.Right < 2) or (I > FSections.Count) then
- R.Right := ClientWidth;
- if I <= SectionCount then
- Section[I-1].fPaintRect := R;
-
- if ((Style = bhsRadio) and (FItemIndex = I-1))
- or ((Style = bhsButton) and (bhSectionPressed = I-1)) then begin
- fPushRect := R;
- {$IFDEF WIN32}
- case DrawingStyle of
- bhsDefault :
- DrawFrameControl(Handle, R, DFC_BUTTON, DFCS_BUTTONPUSH or DFCS_PUSHED);
- bhsThin :
- DrawEdge(bhDraw.Canvas.Handle, R, EDGE_SUNKEN, BF_BOTTOM or BF_TOP or BF_LEFT or BF_RIGHT or BF_MIDDLE);
- bhsFlat :
- begin
- inc(R.Right, 2);
- DrawEdge(bhDraw.Canvas.Handle, R, EDGE_SUNKEN, BF_BOTTOM or BF_TOP or BF_LEFT or BF_RIGHT or BF_MIDDLE);
- dec(R.Right, 2);
- end;
- bhsEtched :
- begin
- inc(R.Right, 2);
- DrawEdge(bhDraw.Canvas.Handle, R, EDGE_SUNKEN, BF_LEFT or BF_RIGHT or BF_BOTTOM or BF_TOP or BF_MIDDLE);
- dec(R.Right, 2);
- end;
- end;
- {$ELSE}
- DrawButtonFrame(bhDraw.Canvas,R,True,False,bsNew);
- {$ENDIF}
- end else
- if Style <> bhsNone then begin
- {$IFDEF WIN32}
- case DrawingStyle of
- bhsDefault :
- DrawFrameControl(bhDraw.Canvas.Handle, R, DFC_BUTTON, DFCS_BUTTONPUSH);
- bhsThin :
- DrawEdge(bhDraw.Canvas.Handle, R, EDGE_ETCHED, BF_BOTTOM or BF_TOP or BF_LEFT or BF_RIGHT or BF_MIDDLE);
- bhsFlat :
- begin
- inc(R.Right, 2);
- DrawEdge(bhDraw.Canvas.Handle, R, EDGE_ETCHED, BF_BOTTOM or BF_TOP or BF_LEFT or BF_RIGHT or BF_MIDDLE);
- dec(R.Right, 2);
- end;
- bhsEtched :
- begin
- inc(R.Right, 2);
- DrawEdge(bhDraw.Canvas.Handle, R, EDGE_ETCHED, BF_BOTTOM or BF_TOP or BF_MIDDLE);
- dec(R.Right, 2);
- if (I <= FSections.Count) and ((FItemIndex <> I) or (Style <> bhsRadio)) then begin
- Pen.Color := clBtnShadow;
- MoveTo(R.Right - 2, R.Top + 3);
- LineTo(R.Right - 2, R.Bottom - 3);
- Pen.Color := clBtnHighlight;
- MoveTo(R.Right - 1, R.Top + 3);
- LineTo(R.Right - 1, R.Bottom - 3);
- end;
- if I = 1 then begin
- Pen.Color := clBtnShadow;
- MoveTo(R.Left, R.Top + 1);
- LineTo(R.Left, R.Bottom - 1);
- Pen.Color := clBtnHighlight;
- MoveTo(R.Left + 1, R.Top + 1);
- LineTo(R.Left + 1, R.Bottom - 2);
- end;
- if I > FSections.Count then begin
- Pen.Color := clBtnShadow;
- MoveTo(R.Right - 1, R.Top + 1);
- LineTo(R.Right - 1, R.Bottom - 1);
- end;
- end;
- end;
- {$ELSE}
- DrawButtonFrame(bhDraw.Canvas,R,False,False,bsNew);
- {$ENDIF}
- end else begin
- {$IFDEF WIN32}
- case DrawingStyle of
- bhsDefault :
- DrawFrameControl(Handle, R, DFC_BUTTON, DFCS_BUTTONPUSH or DFCS_PUSHED);
- bhsThin :
- DrawEdge(bhDraw.Canvas.Handle, R, EDGE_ETCHED, BF_BOTTOM or BF_TOP or BF_LEFT or BF_RIGHT or BF_MIDDLE);
- bhsFlat :
- begin
- inc(R.Right, 2);
- DrawEdge(bhDraw.Canvas.Handle, R, EDGE_ETCHED, BF_BOTTOM or BF_TOP or BF_LEFT or BF_RIGHT or BF_MIDDLE);
- dec(R.Right, 2);
- end;
- bhsEtched :
- begin
- inc(R.Right, 2);
- DrawEdge(bhDraw.Canvas.Handle, R, EDGE_ETCHED, BF_BOTTOM or BF_TOP or BF_MIDDLE);
- dec(R.Right, 2);
- if I <= FSections.Count then begin
- Pen.Color := clBtnShadow;
- MoveTo(R.Right - 2, R.Top + 3);
- LineTo(R.RIght - 2, R.Bottom - 3);
- Pen.Color := clBtnHighlight;
- MoveTo(R.Right - 1, R.Top + 3);
- LineTo(R.RIght - 1, R.Bottom - 3);
- end;
- if I = 1 then begin
- Pen.Color := clBtnShadow;
- MoveTo(R.Left, R.Top + 1);
- LineTo(R.Left, R.Bottom - 1);
- Pen.Color := clBtnHighlight;
- MoveTo(R.Left + 1, R.Top + 1);
- LineTo(R.Left + 1, R.Bottom - 2);
- end;
- if I > FSections.Count then begin
- Pen.Color := clBtnShadow;
- MoveTo(R.Right - 1, R.Top + 1);
- LineTo(R.Right - 1, R.Bottom - 1);
- end;
- end;
- end;
- {$ELSE}
- DrawButtonFrame(bhDraw.Canvas,R,True{False},False{True},bsNew);
- {$ENDIF}
- end;
-
- {$IFNDEF WIN32}
- TextRect(Rect(R.Left+1, R.Top+1, R.Right-1, R.Bottom-1), R.Left+3, Y, '');
- {$ENDIF}
-
- if FWordWrap then
- WM := DT_WORDBREAK
- else
- WM := DT_VCENTER or DT_SINGLELINE;
-
- R2 := Rect(R.Left+2, R.Top+2, R.Right-4, R.Bottom-1);
-
- if (Images <> nil) and (Img <> -1) then begin
- BDim.x := Images.Width;
- BDim.y := Images.Height;
- if (BDim.x <> 0) and (BDim.y <> 0) then begin
- dec(R2.Right,BDim.X + 2);
- H := R2.Bottom-R2.Top;
- if H <= BDim.y then
- T := R2.Top
- else
- T := R2.Top + (H - BDim.y) shr 1;
- Images.Draw(bhDraw.Canvas,R2.Right + 2,T,Img);
- end;
- end;
-
- if TextMargin < (R2.Right-R2.Left) div 2 then
- InflateRect(R2, -TextMargin, 0);
-
- if S <> '' then begin
- if not WordWrap then
- S := GetDisplayString(bhDraw.Canvas,S,1,R2.Right-R2.Left);
- StrPCopy(P,S);
- DoOnChangeTextAttr(bhDraw.Canvas,I-1);
- end else
- StrCopy(P,'');
- DrawText(Handle, @P, StrLen(@P), R2, AL or WM);
-
- until R.Right = ClientWidth;
- end;
- Canvas.CopyMode := cmSrcCopy;
- Canvas.CopyRect(ClientRect, bhDraw.Canvas, ClientRect);
- end;
-
- procedure TOvcButtonHeader.SetBorderStyle(Value : TBorderStyle);
- begin
- if (Value <> FBorderStyle) then begin
- FBorderStyle := Value;
- RecreateWnd;
- end;
- end;
-
- {$IFDEF Win32}
- procedure TOvcButtonHeader.SetDrawingStyle(
- const Value: TOvcBHDrawingStyle);
- begin
- FDrawingStyle := Value;
- Refresh;
- end;
- {$ENDIF}
-
- procedure TOvcButtonHeader.SetImages(Value : TImageList);
- begin
- if Value <> FImages then begin
- if FImages <> nil then
- FImages.OnChange := nil;
- FImages := Value;
- if FImages <> nil then
- FImages.OnChange := bhCollectionChanged;
- Refresh;
- end;
- end;
-
- procedure TOvcButtonHeader.SetItemIndex(Value : Integer);
- begin
- if (Value <> FItemIndex) and (Value < FSections.Count) then begin
- FItemIndex := Value;
- DoOnClick;
- end;
- end;
-
- procedure TOvcButtonHeader.SetSection(Index: Integer; Value: TOvcButtonHeaderSection);
- begin
- FSections[Index] := Value;
- end;
-
- procedure TOvcButtonHeader.SetStyle(Value : TOvcButtonHeaderStyle);
- begin
- if (Value <> FStyle) then begin
- FStyle := Value;
- Refresh;
- end;
- end;
-
- procedure TOvcButtonHeader.SetTextMargin(Value : Integer);
- begin
- if (Value <> FTextMargin) and (Value >= 0) then begin
- FTextMargin := Value;
- Refresh;
- end;
- end;
-
- procedure TOvcButtonHeader.SetWordWrap(Value : Boolean);
- begin
- if (Value <> FWordWrap) then begin
- FWordWrap := Value;
- Refresh;
- end;
- end;
-
- procedure TOvcButtonHeader.WMNCHitTest(var Msg : TWMNCHitTest);
- begin
- inherited;
-
- bhHitTest := SmallPointToPoint(Msg.Pos);
- end;
-
- procedure TOvcButtonHeader.WMSetCursor(var Msg : TWMSetCursor);
- var
- Cur : hCursor;
- I : Integer;
- X : Integer;
- begin
- Cur := 0;
- bhResizeSection := 0;
- bhHitTest := ScreenToClient(bhHitTest);
- X := 2;
- if Msg.HitTest = HTCLIENT then
- for I := 0 to FSections.Count - 1 do begin
- Inc(X, Section[I].Width);
- bhMouseOffset := X - (bhHitTest.X + 2);
- if Abs(bhMouseOffset) < 4 then begin
- Cur := LoadCursor(0, IDC_SIZEWE);
- bhResizeSection := I;
- Break;
- end;
- end;
-
- bhCanResize := (FAllowResize or (csDesigning in ComponentState)) and (Cur <> 0);
- if bhCanResize then begin
- SetCursor(Cur);
- Msg.Result := 1;
- end else
- inherited;
- end;
-
- end.
-